import axios from '@/libs/api.request'
import qs from 'qs'

export const getTableData = () => {
  return axios.request({
    url: 'get_table_data',
    method: 'get'
  })
}

//注册
export const regist =(formData)=> {
  console.log(JSON.stringify(formData))
  const data = qs.stringify({
    name:formData.name,
    phone:formData.phone,
    username:formData.username,
    password:formData.password,
    confirmPwd:formData.confirmPwd,
    identityId:formData.identity,
    subjectId:formData.subjectId
  })
   //console.log(data)
  return axios.request({
    url: '/regist.zhtml', 
//    emulateJSON:true,
    data,
    method: 'post'
  })
}
// 首页统计
export const statisticAllData = () => {
  const data = qs.stringify({})
  return axios.request({
    url: '/statistic/statisticAll',
    data,
    method: 'post'
  })
}
export const statisticAllNotice = () => {
  const data = qs.stringify({})
  return axios.request({
    url: '/statistic/statisticAllNotice',
    data,
    method: 'post'
  })
}
// 删除方法
export const commentDel = (url, ids) => {
  const params = {
    ids:`${ids}`
  }
  return axios.request({
    url:url,
    params,
    method: 'delete'
  })
}

export const getIpByManagerId = (managerId) => {
  return axios.request({
    url: `/ip-address/${managerId}`,
    method: 'get'
  })
}

// 启用禁用方法
export const handle = (url, ids) => {
  const data = qs.stringify({
    ids
  },{ indices: false })
  return axios.request({
    url:url,
    data,
    method: 'put'
  })
}


// 删除方法
export const commentDels = (url, ids,states) => {
  const data = qs.stringify({
    ids,
    states
  },{ indices: false })
  return axios.request({
    url:url,
    data,
    method: 'post'
  })
}
// 管理员列表
export const ManagerTableData = (pageSize, currentPage,searchText) => {
  const params = {
    pageSize,
    currentPage,
    name: searchText
  }
  return axios.request({
     url: '/manager/list',
     params,
     method: 'get'
  })
}

//文章列表
export const articleTableData = (pageSize, currentPage,searchText) => {
  const params = {
    pageSize,
    currentPage,
    name:searchText
  }
  return axios.request({
    url: '/article/list',
    params,
    method: 'get'
  })
}

export const removeCurrentPic = (formData) => {
  const data = qs.stringify({
    id : formData.id,
    headPic:formData.headPic
  })
  console.log(JSON.stringify(data))
  return axios.request({
    url: '/current/removeCurrentPic',
    data,
    method: 'post'
  }) 
}

//上传文件
export const uploadFile = (file) => {
  let formData = new FormData()
  formData.append('file', file)
  return axios.request({
    url: '/file/upload',
    data: formData,
    method: 'post'
  })
}

//保存文章
export const saveArticle = (formData) => {
 return axios.request({
   url: '/article/save',
   data:formData,
   method: 'post'
 })
}

//修改文章 
export const updateArticle = (formData) => {
  return axios.request({
    url: '/article/update',
    data:formData,
    method: 'put'
  })
}

//获取文章全部类型
export const getAllArticleType = () => {
  return axios.request({
    url: '/article/getAllArticleType',
    method: 'get'
  })
}


// 当前登录人编辑
export const updateCurrent = (formData) => {
   //console.log('777'+JSON.stringify(formData));
  const data = qs.stringify({
    id:formData.userId,
    name:formData.name,
    phone:formData.phone,
//    oldpassword:formData.oldpassword,
//    password:formData.password,
//    confirmPwd:formData.confirmPwd,
    access:formData.access
  },{ indices: false })
  // console.log('666666'+JSON.stringify(data));
  return axios.request({
    url: '/current/updateCurrent',
    data,
    method: 'post'
  }) 
}

// 当前登录人编辑密码
export const updateCurrent1 = (formData) => {
   //console.log('777'+JSON.stringify(formData));
  const data = qs.stringify({
    id:formData.userId,
    oldPassword:formData.oldPassword,
    password:formData.newPassword,
    confirmPwd:formData.confirmPwd,
    access:formData.access
  },{ indices: false })
   //console.log('666666'+JSON.stringify(data));
  return axios.request({
    url: '/current/updateCurrent1',
    data,
    method: 'post'
  })
}




// 评分列表
export const customTableData = (pageSize, currentPage,searchText) => {
  const data = qs.stringify({
    pageSize,
    currentPage,
    name:searchText
  })
  return axios.request({
    url: '/student/openCustomTable',
    data,
    method: 'post'
  })
}

// 评分详情
export const recordTableData = (userId,tableCurrentPage) => {
  var studentId = userId;
  var currentPage = tableCurrentPage;
  const data = qs.stringify({
    studentId,
    pageSize:5,
    currentPage
    //name:searchText
  })
  return axios.request({
    url: '/student/recordTableData',
    data,
    method: 'post'
  })
}

// 成绩列表
export const resultsTableData = (pageSize, currentPage,startTime,endTime,searchText,examTimes,examStatus,states) => {
  console.log(JSON.stringify(states))
  var state = states
  const data = qs.stringify({
    orderByClause:'examTime DESC',
    examTimes,
    examStatus,
    pageSize,
    currentPage,
    startTime,
    endTime,
    state,
    name:searchText
  })
  console.log(JSON.stringify(data))
  return axios.request({
    url: '/results/openResultsTable',
    data,
    method: 'post'
  })
}

// 查询全部考试时间
export const selectExamTime = (state) => {
  //console.log('777'+JSON.stringify(state))
  const data = qs.stringify({
    state
  })
  return axios.request({
    url: '/results/selectExamTime',
    data,
    method: 'post'
  })
}
// 模糊查询学生姓名
export const serchStudentByName = (query) => {
  var studentName = query;
  //console.log(JSON.stringify(studentName))
  const data = qs.stringify({
   studentName
  })
  return axios.request({
    url: '/student/serchStudentByName',
    data,
    method: 'post'
  })
}

//新增成绩
export const addResult = (formData,strTime) => {
 // console.log(JSON.stringify(formData))
 var endTime = strTime;
  const data = qs.stringify({
    studentId:formData.studentId,
    chinese:formData.chinese,
    math:formData.math,
    english:formData.english,
    political:formData.political,
    history:formData.history,
    geographic:formData.geographic,
    examStatus:formData.examStatus,
    //examTime:formData.examTime,
    endTime
  })
  console.log(JSON.stringify(data))
  return axios.request({
    url: '/results/addResult',
    data,
    method: 'post'
  })
}

//编辑成绩
export const updateResult = (formData) => {
    const data = qs.stringify({
    id:formData.id,
    chinese:formData.chinese,
    math:formData.math,
    english:formData.english,
    political:formData.political,
    history:formData.history,
    geographic:formData.geographic
  })
    console.log(JSON.stringify(data))
  return axios.request({
    url: '/results/updateResult',
    data,
    method: 'post'
  })
}

export const savaResults = (url, resultsDto) => {
  let data = qs.stringify({
    resultsDto
  },{ indices: false })
  return axios.request({
    url:url,
    data,
    method: 'post'
  })
}
// 公告列表
export const NoticeTableData = (pageSize, currentPage,startTime,endTime,searchText,state) => {
  const data = qs.stringify({
    orderByClause:'createtime DESC',
    pageSize,
    currentPage,
    startTime,
    endTime,
    name:searchText,
    state
  })
  console.log('666666'+JSON.stringify(data))
  return axios.request({
    url: '/notice/openNoticeTable',
    data,
    method: 'post'
  })
}
//保存公告
export const addNotice = (formData,targetKeys) => {
  //console.log(JSON.stringify(targetKeys))
  const data = qs.stringify({
    notice:formData.notice,
    state:formData.state,
    rose:formData.rose,
    managerIds:targetKeys
  },{ indices: false })
  return axios.request({
    url: '/notice/addNotice',
    data,
    method: 'post'
  })
}

// 模糊查询学生姓名
export const getStudentName = () => {
  //var studentName = query;
  //console.log(JSON.stringify(studentName))
  const data = qs.stringify({
  })
  return axios.request({
    url: '/student/getStudentName',
    data,
    method: 'post'
  })
}


export const teacherArrTableData = (userId,tableCurrentPage) => {
  var courseId = userId;
  var currentPage = tableCurrentPage;
  const data = qs.stringify({
    courseId,
    pageSize:5,
    currentPage
    //name:searchText
  })
  return axios.request({
    url: '/course/teacherArrTableData',
    data,
    method: 'post'
  })
}

export const studenrArrTableData = (userId,tableCurrentPage) => {
  var courseId = userId;
  var currentPage = tableCurrentPage;
  const data = qs.stringify({
    courseId,
    pageSize:5,
    currentPage
    //name:searchText
  })
  return axios.request({
    url: '/course/studenrArrTableData',
    data,
    method: 'post'
  })
}

export const appoinPeople = (appoinId,courseId,state) => {
  const data = qs.stringify({
    appoinId,
    courseId,
    state
    //name:searchText
  })
  return axios.request({
    url: '/course/appoinPeople',
    data,
    method: 'post'
  })
}
//保存班级
export const addCourse = (formData,targetKeys) => {
  console.log(JSON.stringify(formData))
  const data = qs.stringify({
    className:formData.className,
    cname:formData.cname,
    remark:formData.remark,
    teacherIds:targetKeys
  },{ indices: false })
  return axios.request({
    url: '/course/addCourse',
    data,
    method: 'post'
  })
}
//保存班级
export const updateCourse = (formData,targetKeys) => {
  console.log(JSON.stringify(formData))
  const data = qs.stringify({
    id:formData.id,
    className:formData.className,
    cname:formData.cname,
    remark:formData.remark,
    teacherIds:targetKeys
  },{ indices: false })
  return axios.request({
    url: '/course/updateCourse',
    data,
    method: 'post'
  })
}

//查询消息数量
/*export const selectNewsCount = () => {

  return axios.request({
    url: '/news/selectNewsCount',
    //data,
    method: 'post'
  })
}*/

export const newsTableData = (pageSize, currentPage,startTime,endTime) => {
  //alert(2)
  const data = qs.stringify({
    orderByClause:'createTime DESC',
    pageSize,
    currentPage,
    startTime,
    endTime
  })
  return axios.request({
    url: '/news/openNewsTable',
    data,
    method: 'post'
  })
}













export const getDragList = () => {
  return axios.request({
    url: 'get_drag_list',
    method: 'get'
  })
}

export const errorReq = () => {
  return axios.request({
    url: 'error_url',
    method: 'post'
  })
}

export const saveErrorLogger = info => {
  return axios.request({
    url: 'save_error_logger',
    data: info,
    method: 'post'
  })
}
